<template>
  <div class="report-form-content">
    <van-tabs :active="active1" type="card" :animated="true" :swipeable="true">
      <van-tab title="合同补充协议">
        <van-tabs :active="active2">
          <van-tab title="补充协议">
            <div class="shenpilist" v-if="obj">
              <label>补充协议经办人：</label>
              <span>{{ showIdLabel(userList, obj.supplementalUserId, 'name') }}</span>
            </div>
            <div class="shenpilist" v-if="obj">
              <label>补充协议经办部门：</label>
              <span>{{ showIdLabel(organizationList, obj.supplementalDepartmentId, 'organizationName') }}</span>
            </div>
            <div class="shenpilist" v-if="obj">
              <label>补充协议编号：</label>
              <span>{{ obj.supplementalContractNo }}</span>
            </div>
            <div class="shenpilist" v-if="obj">
              <label>补充协议名称：</label>
              <span>{{ obj.supplementalContractName }}</span>
            </div>
            <div class="shenpilist"  v-if="obj">
              <label>补充协议创建时间：</label>
              <span>{{ obj.createTime }}</span>
            </div>
            <div class="shenpilist"  v-if="obj">
              <label>补充协议增加金额：</label>
              <span>{{ obj.supplementalAmount }}</span>
            </div>
            <div class="shenpilist" v-if="obj">
              <label>补充原因：</label>
            </div>
            <div class="shenpilist"  v-if="obj">
              <span>{{ obj.supplementalReason }}</span>
            </div>
          </van-tab>
          <van-tab title="补充协议附件">
            <ul class="files-list" v-if="oFile && oFile.length > 0">
              <li v-for="item in oFile" :key="item.id">
                <div class="files-list-1">
                  <div class="files-list-content">
                    <p><span class="list-content-hindline">{{ item.original }}</span> {{ bytesToSize(item.size) }}</p>
                    <p><span>上传于 {{ item.createTime }}</span></p>
                  </div>
                </div>
              </li>
            </ul>
            <van-empty description="暂无附件" v-else />
          </van-tab>
          <van-tab title="协议合同信息">
            <div class="shenpilist" v-if="obj">
              <label>合同内容：</label>
            </div>
            <div class="shenpilist"  v-if="obj">
              <span v-html="obj.supplementalContent"></span>
            </div>
          </van-tab>
        </van-tabs>
      </van-tab>
      <van-tab title="合同详情">
        <contractMainDetail v-if="obj" :contractInitialId="obj.contractInitialId" />
      </van-tab>
    </van-tabs> 
  </div>
</template>
<script setup>
import {ref, watch} from 'vue'
import {doGet} from "@/config/http";
import {svc, showIdLabel, getListPageSize, bytesToSize} from "@/config/common";
import { useRoute, useRouter } from 'vue-router'
import contractMainDetail from '@/h5/components/contractMainDetail.vue'
import initListStore from '@/store/modules/initList'

const props = defineProps({
  contractSupplementalId: {
    required: true,
    type: String,
  }
})
let active1 = ref(0)
let active2 = ref(0)
let oFile = ref([])
let obj = ref(null)
let userList = initListStore().userList
let organizationList = initListStore().organizationList

// const initList = async () => {
//   let p1= doGet(svc, '/user/page', {pageSize: getListPageSize()}, false) // 用户
//   let p2 = doGet(svc, '/organization/page', {pageSize: getListPageSize()}, false) // 部门
//   let resArray = await Promise.all([p1, p2])
//   userList.value = resArray[0]['records']
//   organizationList.value = resArray[1]['records']
// }

const initObj = async (val) =>  {
  if (val) {
    obj.value = await doGet(svc, `/contract-initial-supplemental/${val}`, {}, true)
    oFile.value = await doGet(svc, '/contract-initial-supplemental-attachment/listByField', {field: 'contractInitialSupplementalId', values: obj.value.id}, false)
  }
}

watch(() => props.contractSupplementalId, async val => {
  await initObj(val)
  // await initList()
},{immediate:true})

</script>

<style scoped lang="scss">
.report-form-content {
  width: 100%;
  height: 52vh;
  overflow-x: hidden;
  overflow-y: auto;
  margin-top: 1.25rem;
}
.update-log {
  width: 100%;
  margin: 30px 0;
}
.tabs-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tabs-form-head span {
  font-size: 18px;
  color: #303133;
  font-weight: bold;
}
.shenpilist {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--van-cell-background);
  box-sizing: border-box;
  width: 100%;
  padding: var(--van-cell-vertical-padding) var(--van-cell-horizontal-padding);
  overflow: hidden;
  color: var(--van-cell-text-color);
  font-size: var(--van-cell-font-size);
  // line-height: var(--van-cell-line-height);
  border-bottom: 1px solid var(--van-border-color);;
  & label {
    color: var(--van-field-label-color);
    // text-align: left;
    word-wrap: break-word;
    font-weight: 700;
  }
  & span {
    display: block;
    box-sizing: border-box;
    // width: 100%;
    color: var(--van-field-input-text-color);
    line-height: inherit;
    // text-align: left;
    background-color: transparent;
    border: 0;
    resize: none;
    -webkit-user-select: auto;
    user-select: auto;
  }
}
.files-list {
  li {
    width: 100%;
    color: var(--van-gray-6);
    .files-list-1 {   
      .files-list-content {
        width: 95%;
        & p {
          padding-left: .9375rem;
          padding-top: .625rem;
          margin: 0;
          display: flex;
          align-items: center;
        }
        .list-content-hindline {
          font-size: 1rem;
          padding-right: .9375rem;
          font-weight: bold;
          color: #000;
        }
      }
    }
  }
}
</style>
